package com.mjee.action.struts2;

import java.io.IOException;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/**
 * Abstract base action support.
 *
 * @author 	<a href="mailto:shixi.zhang@f-club.com">ZhangShixi</a>
 * @version 1.00, 2012-6-20
 * @since 	JDK1.5
 */
public class AbstractAction extends ActionSupport {

	/** serial version UID */
	private static final long serialVersionUID = 546256161266207143L;

	/**
	 * Succeed return flag.
	 */
	public static final String SUCCESS = "success";
	/**
	 * Failed return flag.
	 */
	public static final String FAIL = "fail";
	/**
	 * Key name in session that point to current login user. 
	 */
	public static final String USER_SESSION_KEY = "login_user";
	/**
	 * Default page index. 
	 */
	public static final int DEFAULT_PAGE_INDEX = 1;
	/**
	 * Default page size.
	 */
	public static final int DEFAULT_PAGE_SIZE = 10;
	
	// ----protected methods -----------------------------------
	protected Map<String, Object> getSession() {
		return ActionContext.getContext().getSession();
	}
	
	protected void send403Error() throws IOException {
		doSendError(HttpServletResponse.SC_FORBIDDEN);
	}
	
	private void doSendError(int code) throws IOException {
		ServletActionContext.getResponse().sendError(code);
	}
}
